package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import java.util.Locale;

import org.antlr.v4.runtime.misc.NotNull;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.DistinctContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ExpressionContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.FunctionNameContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.StreamAllColumnsContext;

/**
 * function 语法遍历
 * @author zwd
 *
 */
public class FunctionVisitor extends AbsCQLParserBaseVisitor<FunctionContext>{

	private FunctionContext context = null;
	
	public FunctionVisitor() {
		context = new FunctionContext();
	}
	
	@Override
	protected FunctionContext defaultResult() {
		return context;
	}
	
	@Override
	public FunctionContext visitFunctionName(@NotNull FunctionNameContext ctx) {
		context.setName(ctx.getText().toLowerCase(Locale.US));
		return context;
	}
	
	@Override
	public FunctionContext visitDistinct(@NotNull DistinctContext ctx) {
		context.setDistinct(true);
		return context;
	}
	
	@Override
	public FunctionContext visitExpression(@NotNull ExpressionContext ctx) {
		ExpressionVisitor visitor = new ExpressionVisitor();
        context.getArguments().add(visitor.visit(ctx));
        return context;
	}
	
	@Override
	public FunctionContext visitStreamAllColumns(StreamAllColumnsContext ctx) {
		StreamAllColumnsVisitor visitor = new StreamAllColumnsVisitor();
        context.setAllColumns(visitor.visit(ctx));
        return context;
	}

}
